
import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:uitest/config/service_url.dart';
import 'dart:io';

//import 'package:uitest/navigator/LoadingDialog.dart';

// 通用接口请求模版
Future request(url, {formData}) async {
  try {
    print('开始获取数据..............');
    Response response;
    Dio dio = new Dio();
    dio.options.contentType =
        ContentType.parse('application/x-www-form-urlencoded');
    if (formData == null) {
      response = await dio.post(servicePath[url]);
    } else {
      response = await dio.post(servicePath[url], data: formData);
    }
    if (response.statusCode == 200) {
      return response.data;
    } else {
      throw Exception('后端接口出现异常。');
    }
  } catch (e) {
    return print('ERROR:===========>$e');
  }
}

Future getHomePageContent(BuildContext context) async {
    try {
      print('开始获取首页数据·············');

      //  showDialog<Null>(
      //     context: context, //BuildContext对象
      //     barrierDismissible: false,
      //     builder: (BuildContext context) {
      //         return new LoadingDialog( //调用对话框
      //             text: '正在获取详情...',
      //         );
      //   });


      Response response;
      Dio dio = new Dio();
      dio.options.contentType = ContentType.parse('application/x-www-form-urlencoded');
      var formData = {'lon':'115.02932','lat':'35.76189'};
      response = await dio.post(
        servicePath['homePageContext'],
        data: formData,
      );

      if (response.statusCode == 200){
        // Navigator.pop(context); //关闭对话框
        print(response.data.toString());
        return response.data;
      }else {
        throw Exception('后端接口出现异常，请检测代码和服务器情况``````````');
      }
      
    } catch (e) {

      return print('ERROR:======>${e}');
    }
}

Future getHomePageBeloConten() async{
  try {
    print('开始获取下拉列表数据.................');
    Response response;
    Dio dio = new Dio();
    dio.options.contentType = ContentType.parse('application/x-www-form-urlencoded');
    int page = 1;
    response = await dio.post(
      servicePath['homePageContext'],
        data: page,
    );

    if (response.statusCode == 200){
        // Navigator.pop(context); //关闭对话框
        print(response.data.toString());
        return response.data;
      }else {
        throw Exception('后端接口出现异常，请检测代码和服务器情况``````````');
      }
  } catch (e) {
    return print('ERROR:======>${e}');
  }
}